package com.example.prison.mapper;

import com.example.prison.entity.PersonnelManagement;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【personnel_management】的数据库操作Mapper
* @createDate 2023-05-26 16:07:49
* @Entity com.example.prison.entity.PersonnelManagement
*/
@Mapper
public interface PersonnelManagementMapper extends BaseMapper<PersonnelManagement> {

    @Select("select * from personnel_management where is_push_people = 1 order by id desc")
    List<PersonnelManagement> get();

    @Select("select * from personnel_management order by id desc")
    List<PersonnelManagement> getAll();

    @Select("select * from personnel_management where is_sentry = 1 order by id desc")
    List<PersonnelManagement> getSentry();

    @Insert("insert into personnel_management(name, sex, post, phone, department, is_push_people, sentry_post, is_sentry, password, role) " +
            "values (#{name}, #{sex}, #{post}, #{phone}, #{department}, #{isPushPeople}, #{sentryPost}, #{isSentry}, #{password}, #{role})")
    int add(PersonnelManagement personnel);

    @Delete("<script>delete from personnel_management where id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deletePersonnel(@Param("ids") Integer[] ids);

    @Delete("delete from personnel_management where id = #{id}")
    void deleteOneById(@Param("id") Integer ids);

    @Update("update personnel_management set name=#{personnel.name}, sex=#{personnel.sex}, post=#{personnel.post}, phone=#{personnel.phone}, department=#{personnel.department}, is_push_people=#{personnel.isPushPeople}, sentry_post=#{personnel.sentryPost}, is_sentry=#{personnel.isSentry}, password=#{personnel.password}, role=#{personnel.role} where id = #{id}")
    int updatePersonnel(PersonnelManagement personnel,Integer id);

    @Update("update personnel_management set name=#{personnel.name}, sex=#{personnel.sex}, post=#{personnel.post}, phone=#{personnel.phone}, department=#{personnel.department}, is_push_people=#{personnel.isPushPeople}, sentry_post=#{personnel.sentryPost}, is_sentry=#{personnel.isSentry}, password=#{personnel.password}, role=#{personnel.role} where id = #{id}")
    int updatePersonnelFail(PersonnelManagement personnel,Integer id);

    @Select("select * from personnel_management where name like concat('%',#{name},'%') order by id desc")
    List<PersonnelManagement> getByName(@Param("name") String name);

    @Select("select * from personnel_management where name=#{name} order by id desc")
    List<PersonnelManagement> getBySameName(@Param("name") String name);

    @Select("select * from personnel_management where name=#{name}")
    PersonnelManagement getOneByName(@Param("name") String name);

    @Select("select * from personnel_management where phone=#{phone}")
    PersonnelManagement getOneByPhone(@Param("phone") String phone);

    @Select("select * from personnel_management where name=#{name} and phone=#{phone}")
    PersonnelManagement getOneByNameAndPhone(@Param("name") String name, @Param("phone") String phone);

    @Select("select * from personnel_management where id=#{id}")
    PersonnelManagement getById(@Param("id") Integer id);

}




